package com.fjrcloud.service;

import com.fjrcloud.dao.BasePriceDao;
import com.fjrcloud.entity.BasePrice;
import com.fjrcloud.entity.PriceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by shengjian.lin on 17-2-11.
 */
@Service
public class BasePriceService {

    @Autowired
    private BasePriceDao basePriceDao;

    public BasePrice get(Integer id){
        return basePriceDao.findOne(id);
    }
    public BasePrice get(PriceType type){
        return basePriceDao.findByType(type);
    }
    public List<BasePrice> list(){
        return (List<BasePrice>) basePriceDao.findAll();
    }

    public void del(Integer id){
        basePriceDao.delete(id);
    }

    public BasePrice save(BasePrice price){

        BasePrice old = get(price.getType());

        if (old != null){
            price.setId(old.getId());
        }

        return basePriceDao.save(price);

    }

}
